<%-- 
    Document   : CreateState
    Created on : Nov 23, 2012, 12:10:51 AM
    Author     : Admin
--%>

<%@page import="Connection.PlanDAL"%>
<%@page import="Connection.PlanDAL"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.DateFormat"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            String dateBegin = "";
            String dateEnd = "";
            String dateOccurence = "";
            String name = request.getParameter("name");
            String kind = request.getParameter("kind");
            String amount = request.getParameter("amount");
            String type = request.getParameter("type");



            dateBegin = dateEnd = dateOccurence = request.getParameter("date");


            DateFormat formatter;
            Date date1, date2, date3;
            formatter = new SimpleDateFormat("yy-MM-dd");

            date1 = (Date) formatter.parse(dateBegin);
            date2 = (Date) formatter.parse(dateOccurence);
            date3 = (Date) formatter.parse(dateEnd);

            if (date3.compareTo(date1) >= 0) {
                try {
                    session.setAttribute("state", "success");

                        PlanDAL.insertOnce(name, type, amount, date2, kind);
                    
                } catch (Exception e) {
                    out.println("Error:" + e.getMessage());


                }
            } else {
                session.setAttribute("state", "Fail");
            }

            response.sendRedirect("BudgetPlanMainPage.jsp");

            //Date time = dateFormat.parse(dateBegin);




        %>
    </body>
</html>
